package com.tms.project.tms.payoffs.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tms.framework.aspectj.lang.annotation.Log;
import com.tms.framework.aspectj.lang.enums.BusinessType;
import com.tms.project.tms.payoffs.domain.ScientificPayoffs;
import com.tms.project.tms.payoffs.service.IScientificPayoffsService;
import com.tms.framework.web.controller.BaseController;
import com.tms.framework.web.domain.AjaxResult;
import com.tms.common.utils.poi.ExcelUtil;
import com.tms.framework.web.page.TableDataInfo;

/**
 * 科研成果Controller
 * 
 * @author xyl
 * @date 2021-03-26
 */
@Controller
@RequestMapping("/tms/payoffs")
public class ScientificPayoffsController extends BaseController
{
    private String prefix = "tms/payoffs";

    @Autowired
    private IScientificPayoffsService scientificPayoffsService;

    @RequiresPermissions("tms:payoffs:view")
    @GetMapping()
    public String payoffs()
    {
        return prefix + "/payoffs";
    }

    /**
     * 查询科研成果列表
     */
    @RequiresPermissions("tms:payoffs:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ScientificPayoffs scientificPayoffs)
    {
        startPage();
        List<ScientificPayoffs> list = scientificPayoffsService.selectScientificPayoffsList(scientificPayoffs);
        return getDataTable(list);
    }

    /**
     * 导出科研成果列表
     */
    @RequiresPermissions("tms:payoffs:export")
    @Log(title = "科研成果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ScientificPayoffs scientificPayoffs)
    {
        List<ScientificPayoffs> list = scientificPayoffsService.selectScientificPayoffsList(scientificPayoffs);
        ExcelUtil<ScientificPayoffs> util = new ExcelUtil<ScientificPayoffs>(ScientificPayoffs.class);
        return util.exportExcel(list, "payoffs");
    }

    /**
     * 新增科研成果
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存科研成果
     */
    @RequiresPermissions("tms:payoffs:add")
    @Log(title = "科研成果", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ScientificPayoffs scientificPayoffs)
    {
        return toAjax(scientificPayoffsService.insertScientificPayoffs(scientificPayoffs));
    }

    /**
     * 修改科研成果
     */
    @GetMapping("/edit/{scientificPayoffsId}")
    public String edit(@PathVariable("scientificPayoffsId") Long scientificPayoffsId, ModelMap mmap)
    {
        ScientificPayoffs scientificPayoffs = scientificPayoffsService.selectScientificPayoffsById(scientificPayoffsId);
        mmap.put("scientificPayoffs", scientificPayoffs);
        return prefix + "/edit";
    }

    /**
     * 修改保存科研成果
     */
    @RequiresPermissions("tms:payoffs:edit")
    @Log(title = "科研成果", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ScientificPayoffs scientificPayoffs)
    {
        return toAjax(scientificPayoffsService.updateScientificPayoffs(scientificPayoffs));
    }

    /**
     * 删除科研成果
     */
    @RequiresPermissions("tms:payoffs:remove")
    @Log(title = "科研成果", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(scientificPayoffsService.deleteScientificPayoffsByIds(ids));
    }
}
